package com.lsf.studentmanagerup.service;

import com.lsf.studentmanagerup.bean.ClassBean;
import com.lsf.studentmanagerup.bean.Student;
import com.lsf.studentmanagerup.dao.ClassBeanDao;
import com.lsf.studentmanagerup.factory.ClassBeanDaoFactory;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * 班级信息服务层
 *
 * @author 李树飞
 */
public class ClassBeanService {

    private ClassBeanDao classBeanDao;

    public ClassBeanService() {
        this.classBeanDao = ClassBeanDaoFactory.getClassBeanDao();
    }

    /**
     * 检查班号是否存在
     * @param id
     * @return
     */
    public boolean checkClassBeanId(String id) {
        try {
            ClassBean classBean = classBeanDao.getClassBeanById(id);
            return null != classBean;
        } catch (SQLException e) {
            System.out.println("数据库连接异常");
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 根据条件查询获取列表信息
     * @param condition
     * @return
     */
    public List<ClassBean> getClassBeanService(Map<String, String> condition) {
        List<ClassBean> classBeanList = null;
        try {
            classBeanList = classBeanDao.getClassBeanByCondition(condition);
        } catch (SQLException e) {
            System.out.println("数据库连接异常");
            e.printStackTrace();
        }
        return classBeanList;
    }

    /**
     * 增加班级
     * @param classBean
     * @return
     */
    public boolean addClassBeanService(ClassBean classBean) {
        try {
            return classBeanDao.addClassBean(classBean) > 0;
        } catch (SQLException e) {
            System.out.println("数据库连接异常");
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 删除班级
     * @param id
     * @return
     */
    public boolean removeClassBeanService(String id) {
        try {
            return classBeanDao.removeClassBeanById(Integer.parseInt(id)) > 0;
        } catch (SQLException e) {
            System.out.println("数据库连接异常");
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 修改班级
     * @param classBean
     * @return
     */
    public boolean updateClassBeanService(ClassBean classBean) {
        try {
            return classBeanDao.updateClassBeanById(classBean) > 0;
        } catch (SQLException e) {
            System.out.println("数据库连接异常");
            e.printStackTrace();
        }
        return false;
    }
}
